//
//  CMISSearchDownload.m
//  Alfresco
//
//  Created by Michael Muller on 10/28/09.
//  Copyright 2009 Michael J Muller. All rights reserved.
//

#import "CMISSearchDownload.h"

@implementation CMISSearchDownload

- (CMISSearchDownload *) initWithSearchPattern:(NSString *)pattern delegate: (id <AsynchronousDownloadDelegate>) del {

	// TODO: escape the pattern -- vulnerable to "SQL (CQL) injection"
	// 1) replace ' with \'
	// 2) encode for embedding in xml

	NSString *cqlTemplate = @"SELECT score() as Relevance, ContentStreamLength FROM Document where contains('%@')";
	NSString *cql = [[NSString alloc] initWithFormat:cqlTemplate, pattern];
	CMISSearchDownload *me = (CMISSearchDownload *) [self initWithQuery:cql delegate:del];
	[cql release];
	
	return me;
}

@end
